package geo.com.geosdkdemo.view.adapter;

/*
 * author: caojunhao
 * date  : 2020/9/1
 * desc  :
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import geo.com.geosdkdemo.R;


public class MyAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<String> lists;

    public MyAdapter(Context context, ArrayList<String> lists){
        this.context=context;
        this.lists=lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_layout,parent,false);
            viewHolder=new ViewHolder();
            viewHolder.content=(TextView) convertView.findViewById(R.id.tv_content);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.content.setText(lists.get(position));
        return convertView;
    }

    public class ViewHolder{
        TextView content;
    }
}
